package com.pay.ioopos.support.serialport.custom;

import android.app.Activity;
import android.view.KeyEvent;

import com.pay.ioopos.App;
import com.pay.ioopos.AppUtils;
import com.pay.ioopos.activity.MainActivity;

/**
 * 指令消费：取消收款
 * @author moyq5
 * @since 2022/8/3
 */
public class SerialPortPayCmd4CancelCer implements SerialPortPayCmdConsumer {

    @Override
    public void consume(byte[] data) {
        SerialPortPayCmd4Cancel cancel  = (SerialPortPayCmd4Cancel)SerialPortPayCmdType.PAY_CANCEL.deserialize(data);
        Activity activity = App.getInstance().getActivity();
        if (activity instanceof MainActivity) {
            AppUtils.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ESCAPE));
            SerialPortPayUtils.response(cancel, CustomCmdStatus.SUCCESS);
            return;
        }
        SerialPortPayUtils.response(cancel, CustomCmdStatus.FAIL);
    }

}
